#/bin/bash

case $1 in
	auth )
		Reg="(User-Name,|User-Password,|CHAP-Password,|CHAP-Challenge,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Framed-IP-Address,)"
		Rg=(User-Name, User-Password, CHAP-Password, CHAP-Challenge, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Framed-IP-Address,)
		Reg_excel="(User-Name,|User-Password,|CHAP-Password,|CHAP-Challenge,|NAS-IP-Address,|NAS-Port,|Service-Type,|NAS-Identifier,|NAS-Port-Type,|NAS-Port-Id,|Called-Station-Id,|Calling-Station-Id,|Framed-IP-Address)"
		Rg_excel=(User-Name, User-Password, CHAP-Password, CHAP-Challenge, NAS-IP-Address, NAS-Port, Service-Type, NAS-Identifier, NAS-Port-Type, NAS-Port-Id, Called-Station-Id, Calling-Station-Id, Framed-IP-Address)
		;;
	start )
		Reg="(User-Name,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Framed-IP-Address,|Event-Timestamp,)"
		Rg=(User-Name, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Framed-IP-Address, Event-Timestamp,)
		Reg_excel="(User-Name,|NAS-IP-Address,|NAS-Port,|NAS-Identifier,|NAS-Port-Type,|NAS-Port-Id,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Framed-IP-Address,|Event-Timestamp)"
		Rg_excel=(User-Name, NAS-IP-Address, NAS-Port, NAS-Identifier, NAS-Port-Type, NAS-Port-Id, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Framed-IP-Address, Event-Timestamp)
		;;
	update )
		Reg="(User-Name,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Acct-Input-Octets,|Acct-Output-Octets,|Acct-Input-Gigawords,|Acct-Output-Gigawords,|Acct-Session-Time,|Framed-IP-Address,|Event-Timestamp,)"
		Rg=(User-Name, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Acct-Input-Octets, Acct-Output-Octets, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Session-Time, Framed-IP-Address, Event-Timestamp,)
		Reg_excel="(User-Name,|NAS-IP-Address,|NAS-Port,|NAS-Identifier,|NAS-Port-Type,|NAS-Port-Id,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Acct-Input-Octets,|Acct-Output-Octets,|Acct-Input-Gigawords,|Acct-Output-Gigawords,|Acct-Session-Time,|Framed-IP-Address,|Event-Timestamp)"
		Rg_excel=(User-Name, NAS-IP-Address, NAS-Port, NAS-Identifier, NAS-Port-Type, NAS-Port-Id, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Acct-Input-Octets, Acct-Output-Octets, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Session-Time, Framed-IP-Address, Event-Timestamp)
		;;
	stop )
		Reg="(User-Name,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Acct-Input-Octets,|Acct-Output-Octets,|Acct-Input-Gigawords,|Acct-Output-Gigawords,|Acct-Session-Time,|Acct-Terminate-Cause,|Framed-IP-Address,|Event-Timestamp,)"
		Rg=(User-Name, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Acct-Input-Octets, Acct-Output-Octets, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Session-Time, Acct-Terminate-Cause, Framed-IP-Address, Event-Timestamp)
		Reg_excel="(User-Name,|NAS-IP-Address,|NAS-Port,|NAS-Identifier,|NAS-Port-Type,|NAS-Port-Id,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Acct-Input-Octets,|Acct-Output-Octets,|Acct-Input-Gigawords,|Acct-Output-Gigawords,|Acct-Session-Time,|Acct-Terminate-Cause,|Framed-IP-Address,|Event-Timestamp)"
		Rg_excel=(User-Name, NAS-IP-Address, NAS-Port, NAS-Identifier, NAS-Port-Type, NAS-Port-Id, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Acct-Input-Octets, Acct-Output-Octets, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Session-Time, Acct-Terminate-Cause, Framed-IP-Address, Event-Timestamp)
		;;
	* )
	echo "parameter error (auth|start|update|stop)"
	echo "ex :"
	echo '	  sh radius_report.sh auth'
	exit
esac


read -p "输入报文:" var



echo ""
echo "----------------------------------"
echo "原始报文:"
#打印输入的原始报文的
#echo ${var} | sed 's/),/\n/g'
echo ${var} | sed 's/(/\n/g' | sed 's/),//g'
echo ""

echo ""
echo "----------------------------------"
echo "匹配必须报文字段:"
#echo ${var} | sed 's/),/\n/g' | grep --color -E ${Reg}
#打印必须匹配的报文并加颜色
echo ${var} | sed 's/(/\n/g' | sed 's/),//g' | grep --color -E ${Reg}
echo ""
echo "匹配必须报文字段结论:"
#在输入的报文里面统计必须匹配 报文的出现次数
for i in `echo ${Rg[*]}`; do
	echo ${i}":" `echo ${var} | grep -cE ${i}`
done

echo ""
echo ${Reg} | awk -F'|' '{print "检查必须字段数:" NF}'
#echo "检查出来实际字段数:" `echo ${var} | sed 's/),/\n/g' | grep -cE ${Reg}`
echo "检查出来实际字段数:" `echo ${var} | sed 's/(/\n/g' | sed 's/),//g'| grep -cE ${Reg}`
echo ""

echo ""
echo "----------------------------------"
echo "匹配对接测试表报文字段:"
#echo ${var} | sed 's/),/\n/g' | grep --color -E ${Reg_excel}
echo ${var} | sed 's/(/\n/g' | sed 's/),//g' | grep --color -E ${Reg_excel}
echo ""
echo "匹配必须报文字段结论:"
for i in `echo ${Rg_excel[*]}`; do
	echo ${i}":" `echo ${var} | grep -cE ${i}`
done

echo ""
echo ${Reg_excel} | awk -F'|' '{print "检查excel字段数:" NF}'
#echo "检查出来实际字段数:" `echo ${var} | sed 's/),/\n/g' | grep -cE ${Reg_excel}`
echo "检查出来实际字段数:" `echo ${var} | sed 's/(/\n/g' | sed 's/),//g' | grep -cE ${Reg_excel}`

echo ""
echo "----------------------------------"
echo "非测试表字段:"
echo ${var} | sed 's/(/\n/g' | sed 's/),//g' | grep -v "\[INFO\] " | grep -v --color -E ${Reg_excel}
